package cn.yr.service.portal.impl;

import cn.yr.domain.entity.Article;
import cn.yr.domain.vo.ArticleTagVo;
import cn.yr.mapper.ArticleMapper;
import cn.yr.service.portal.ArticleService;
import cn.yr.service.portal.TagService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 文章(Article)表服务实现类
 *
 * @author makejava
 * @since 2020-03-05 20:21:24
 */
@Service("articleService")
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {

    @Resource
    private ArticleMapper articleMapper;
    @Resource
    private TagService tagService;

    @Override
    public IPage<ArticleTagVo> selectByPage(Page<ArticleTagVo> page, QueryWrapper<ArticleTagVo> articleQueryWrapper) {
        IPage<ArticleTagVo> articleIPage = articleMapper.selectByPage(page, articleQueryWrapper);
        tagService.setTag(articleIPage.getRecords());
        return articleIPage;
    }

    @Override
    public ArticleTagVo selectById(Integer id) {
        ArticleTagVo article = articleMapper.selectById(id);
        tagService.setTag(article);
        return article;
    }

    /**
     * @author     ：lang
     * @description： 分页查询推荐的文章
     */
    @Override
    public IPage<Article> selectByRecommendPage(Integer pageNumber,Integer pageSize) {
        QueryWrapper<Article> articleQueryWrapper = new QueryWrapper<>();
        articleQueryWrapper.eq("recommend",Article.RECOMMEND);
        articleQueryWrapper.select("title","id");
        Page<Article> page = new Page<>(pageNumber,pageSize);
        IPage<Article> articleIPage = articleMapper.selectPage(page, articleQueryWrapper);
        return articleIPage;
    }

}